package com.ruoyi.common.enums;

/**
 * 库存变动类型枚举
 *
 * 0 - 入库
 * 1 - 出库
 * 2 - 调整
 * 3 - 待检变动
 * 4 - 盘点变动
 */
public enum InventoryChangeType {

    /**
     * 0-入库
     */
    INBOUND(0, "入库"),

    /**
     * 1-出库
     */
    OUTBOUND(1, "出库"),


    /**
     * 2-调整
     */
    ADJUSTMENT(2, "调整"),

    /**
     * 3-待检变动
     */
    INSPECTION(3, "待检变动"),

    /**
     * 4-盘点变动
     */
    STOCKTAKING(4, "盘点变动"),

    /**
     * 5-发货出库
     */
    SHIPMENT_OUTBOUND(5, "发货出库"),
    /**
     * 6-退货出库
     */
    RETURN_OUTBOUND(6, "退货出库"),

    /**
     * 7-换货出库
     */
    EXCHANGE_OUTBOUND(7, "换货出库");

    private final int code;
    private final String description;

    InventoryChangeType(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 获取枚举的整数值
     */
    public int getCode() {
        return code;
    }

    /**
     * 获取枚举的中文/描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 根据 code 获取对应的枚举
     */
    public static InventoryChangeType fromCode(int code) {
        for (InventoryChangeType type : InventoryChangeType.values()) {
            if (type.code == code) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的变动类型code: " + code);
    }

    @Override
    public String toString() {
        return this.name() + "(" + code + " - " + description + ")";
    }
}
